/*******************************************************************************
 * @brief: 程序参数
 * @Author:   aple
 * @Date: 2020-09-02 23:35:00
 * @LastEditors: aple
 * @LastEditTime: 2022-11-12 10:05:20
 * @Verision: 1.0.0.0
 ******************************************************************************/
#define _PROG_MODULE_
#include "prog.h"
#include "par_tab.h"

/*
const prog_seg_type prog_obj =
{
	.tab = prog_tab,
	.seg_size = sizeof(prog_tab_type),
	.seg_min = PROG_SEG_MIN,
	.seg_max = PROG_SEG_MAX,
	.tm_end = 0
};
*/

const prog_manage_type prog_obj = {
	prog_tab,
	sizeof(prog_tab_type),
	PROG_SEG_MIN,
	PROG_SEG_MAX,
	0};

/*******************************************************************************
 * @brief  prog_val_set
 * \param[in] seg : seg
 * \param[in] par_num : par index
 * \param[in] ival : value
 * \retval: none
 *******************************************************************************/
void prog_val_set(uint8_t seg, uint16_t par_num, int32_t ival)
{
	int16_t sval;

	if (seg > prog_obj.seg_max)
		return;

	sval = ival;

	switch (par_num)
	{
	case par_pos(sp):
	{
		if (sval != prog_tab[seg].temp)
		{
			prog_tab[seg].temp = sval;
			eep_par_save(
				EEP_PROG_PAR_BASE + sizeof(prog_tab_type) * seg + 1 * 2,
				prog_tab[seg].temp);
		}
		break;
	}
	case par_pos(st):
	{
		if (sval != prog_tab[seg].time)
		{
			prog_tab[seg].time = ival;
			eep_par_save(
				EEP_PROG_PAR_BASE + sizeof(prog_tab_type) * seg + 0 * 2,
				prog_tab[seg].time);
		}
		break;
	}
	case par_pos(ot):
	{
		if (sval != prog_tab[seg].out_limit)
		{
			prog_tab[seg].out_limit = ival;
			eep_par_save(
				EEP_PROG_PAR_BASE + sizeof(prog_tab_type) * seg + 2 * 2,
				prog_tab[seg].out_limit);
		}
		break;
	}
	}
}

/*******************************************************************************
 * @brief  prog_val_set
 * \param[in] seg : seg
 * \param[in] par_num : par index
 * \retval: value
 *******************************************************************************/
int32_t prog_val_get(uint8_t seg, uint16_t par_num)
{
	if (seg > prog_obj.seg_max)
		return 0;

	switch (par_num)
	{
	case par_pos(sp):
	{
		return prog_tab[seg].temp;
	}
	case par_pos(st):
	{
		return prog_tab[seg].time;
	}
	case par_pos(ot):
	{
		return prog_tab[seg].out_limit;
	}
	}

	return 0;
}
